package com.kit.data.kitopeso.adapter;

import android.graphics.Paint;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.kit.data.kitopeso.R;
import com.kit.data.kitopeso.base.BaseBindingAdapter1;
import com.kit.data.kitopeso.databinding.KitoCouponsItemBinding;
import com.kit.data.kitopeso.obj.KitoCouponsItem;
import com.kit.data.kitopeso.tools.ResUtils;
import com.kit.data.kitopeso.tools.ViewUtils;

import java.util.List;

public class CouponsAdapter extends BaseBindingAdapter1<KitoCouponsItem, KitoCouponsItemBinding> {


    private String ghs;

    private int index = -1;

    public CouponsAdapter(List<KitoCouponsItem> dataList) {
        super(dataList);
    }

    @Override
    protected void bindData(KitoCouponsItemBinding binding, KitoCouponsItem item, int position) {

        binding.tvAmount2.setPaintFlags(binding.tvAmount2.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

        if (TextUtils.isEmpty(ghs)) {
            ghs = ResUtils.s(R.string.ghs);
        }

        String data = item.getCouponGhs();
        String data1 = item.getNewCouponGhs();

        binding.tvAmount.setText(data);
        binding.tvGhs.setText(ghs);

        if (!TextUtils.isEmpty(data) && !data.toUpperCase().contains(ghs.toUpperCase())) {
            data = data + " " + ghs;
        }

        if (!TextUtils.isEmpty(data1) && !data1.toUpperCase().contains(ghs.toUpperCase())) {
            data1 = data1 + " " + ghs;
        }

        binding.tvAmount1.setText(data1);

        binding.tvAmount2.setText(data);

        if (index == position) {
            binding.tvBox.setChecked(true);
        } else {
            binding.tvBox.setChecked(false);
        }

        binding.tvAmountLayout1.setTag(position);

        binding.tvAmountLayout1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ViewUtils.viewScale(v);
                if (onBtnItemClickListener != null) {
                    onBtnItemClickListener.onItemClick((Integer) binding.tvAmountLayout1.getTag());
                }
            }
        });

    }

    @Override
    protected int getItemType(KitoCouponsItem item) {
        return 0;
    }

    @Override
    protected KitoCouponsItemBinding createBinding(LayoutInflater inflater, ViewGroup parent, int viewType) {
        return KitoCouponsItemBinding.inflate(inflater);
    }

    public String getGhs() {
        return ghs;
    }

    public void setGhs(String ghs) {
        this.ghs = ghs;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }
}
